package org.rcloud.io.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.model.Ditu;
import org.rcloud.io.model.Mapvs;
import org.rcloud.io.service.DituService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Administrator on 2019/1/26.
 */
@RestController
@RequestMapping(value = "/api")
public class DituController {

    @Autowired
    private DituService dituService;
    /*
  *    保存地图
  * */
    @ApiOperation(value="保存地图", notes="根据Map对象保存地图")
    @ResponseBody
    @RequestMapping(value = "/save-mapinfo", produces = {"application/json;charset=UTF-8"})
    public ResultVo saveMap(@RequestBody String params){
//        System.out.print(params);
        String register = JSON.parseObject(params).getString("record");
        Ditu ditu = JSON.parseObject(register, Ditu.class);
        return dituService.saveMap(ditu);
    }

    /*
    *   根据ID查看地图
    * */
    @ApiOperation(value="获取地图详细信息", notes="根据url的id来获取详细信息")
    @ResponseBody
    @RequestMapping(value = "/find-mapIDinfo", produces = {"application/json;charset=UTF-8"})
    public ResultVo getMapID(@RequestBody String params){
        JSONObject object= JSON.parseObject(params);
        return dituService.findMapId(object.getInteger("id"));

    }

    /*
    *   根据经纬度查看地图
    * */
   /* @ApiOperation(value="获取地图详细信息", notes="根据url的经纬度来获取报名详细信息")
    @ResponseBody
    @RequestMapping(value = "/find-mapinfo", produces = {"application/json;charset=UTF-8"})
    public Ditu getMapLDL(@RequestBody String params){
        JSONObject object= JSON.parseObject(params);
        Ditu ditu = dituService.findMapLDL(object.getString("longitude"),object.getString("latitude"));
        return ditu;
    }*/


    /*
    *   根据num获取信息
    * */
    @ApiOperation(value="获取详细信息", notes="根据url的num来获取详细信息")
    @ResponseBody
    @RequestMapping(value = "/findinfo", produces = {"application/json;charset=UTF-8"})
    public PageVo<Ditu> getMapNum(@RequestBody String params){

        String[] num = params.split("=");

        return dituService.findMapNum(num[1]);
    }

    /*
       *   查询type不为代言家庭类型的地图信息
       * */
    @ApiOperation(value="获取详细信息", notes="查询type不为代言家庭的信息")
    @ResponseBody
    @RequestMapping(value = "/findType", produces = {"application/json;charset=UTF-8"})
    public PageVo<Ditu> getMapType(){
        return dituService.findMapTyep();
    }

    /*
    *   查询所有地图信息
    * */
    @ApiOperation(value="获取详细信息", notes="查询所有地图信息")
    @ResponseBody
    @RequestMapping(value = "/findAll", produces = {"application/json;charset=UTF-8"})
    public PageVo<Ditu> findMapAll(){
        return dituService.findMapAll();
    }

    /*
   * 查询
   *
   * */
    @RequestMapping(value = "/select", produces = {"application/json;charset=UTF-8"})
    public ResultVo select(@RequestBody String params) {
        Ditu ditu = JSON.parseObject(params,Ditu.class);
        return dituService.selectByPrimaryKey(ditu);
    }

    /*
    * 根据经纬度查询（经纬度参数）
    *
    * */
    @RequestMapping(value = "/mapByOther", produces = {"application/json;charset=UTF-8"})
    public PageInfo<Ditu> mapByOther(@RequestBody JSONObject params) {//只是JSONObject的别名，也可以写sss
        PageInfo<Ditu> pageInfo = dituService.mapByOther(params);
        return pageInfo;

    }

}
